﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BZV.Core.Net
{
    public class CalcHelper
    {
        /// <summary>
        /// 产生一个某一个区间的随机数
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static int CreateRandNum(int min = 0, int max = 9)
        {
            Random random = new Random(GetRandomSeed());
            return random.Next(min, max);
        }

        /// <summary>
        /// 产生一个在某一个范围里面不同的数
        /// </summary>
        /// <param name="num"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static int CreateRandNumDif(int num, int min = 0, int max = 9)
        {
            int d = CreateRandNum(min, max);
            while (num == d)
            {
                d = CreateRandNum(min, max);
            }
            return d;
        }

        /// <summary>
        /// 产生随机数的种子
        /// </summary>
        /// <returns></returns>
        public static int GetRandomSeed()
        {
            byte[] bytes = new byte[4];
            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
            rng.GetBytes(bytes);
            return BitConverter.ToInt32(bytes, 0);
        }
    }
}
